home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
061-070
/
amok66
/
diskindrive
/
diskindrive.mod
< prev
next >
Wrap
Text File
|
1993-11-04
|
4KB
|
167 lines
(*************************************************************************
:Program. DiskInDrive.mod
:Contents. Tests if a disk is inserted
:Author. Hartmut Goebel
:Address. Aufseßplatz 5, D-8500 Nürnberg 40
:Copyright. Copyright © 1990 by Hartmut Goebel
:Language. Oberon
:Translator. Demo Oberon Compiler 1.17.1
:History. V1.0, 21.01.90, Modula-2
:History. V1.1, 14.07.90, ported to Oberon
:History. V1.2, 17.07.90, +Usage, error-messages
:History. V1.2b, 20 Mar 1991 cosmetics
:History. V1.2c, 21-Dec-91, ported to Oberon 2.13, removed SYSTEM [fbs]
:Support. ChangeState form M2-module TrackDiskSupport
:Usage. DiskInDrive {DF0:|DF1:|DF2:|DF3:}
:Usage. Does not work from WorkBench
:Usage. returns Dos-Errorcode WARN, if no disk in specified drive
*************************************************************************)
MODULE DiskInDrive;
(* $OvflChk- $RangeChk- $StackChk- $NilChk- $ReturnChk- $CaseChk- *)
IMPORT
io,
e: Exec,
es: ExecSupport,
ol: OberonLib,
td: TrackDisk;
VAR
in : BOOLEAN;
adr : LONGINT;
drive,err : INTEGER;
argument : ARRAY 4 OF CHAR;
DiskPort : e.MsgPortPtr;
DiskReqBlock : td.IOExtTDPtr;
(*------ Open TrackDisk: ------*)
PROCEDURE OpenTrackDisk(device: INTEGER): INTEGER;
BEGIN
DiskPort := es.CreatePort("",0);
IF DiskPort = NIL THEN
io.WriteString("CreatePort failed\n");
HALT(10);
END;
(* Assert(DiskPort#NIL,ADR("CreatePort failed")); *)
DiskReqBlock := es.CreateExtIO(DiskPort,SIZE(DiskReqBlock^));
IF DiskReqBlock = NIL THEN
io.WriteString("CreateExtIO failed\n");
HALT(10);
END;
(* Assert(DiskReqBlock#NIL,ADR("CreateExtIO failed")); *)
adr:=e.OpenDevice(td.name,device,DiskReqBlock,
LONGSET{td.allowNon35});
err := DiskReqBlock^.req.error;
IF err#0 THEN
es.DeleteExtIO(DiskReqBlock);
DiskReqBlock := NIL;
es.DeletePort(DiskPort);
DiskPort := NIL;
END;
RETURN err;
END OpenTrackDisk;
(*------ Close TrackDisk: ------*)
PROCEDURE CloseTrackDisk(device: INTEGER);
BEGIN
e.CloseDevice(DiskReqBlock);
es.DeleteExtIO(DiskReqBlock);
DiskReqBlock := NIL;
es.DeletePort(DiskPort);
DiskPort := NIL;
END CloseTrackDisk;
(*------ Get Arguments -------*)
(* Als das Prg entstand, hatte ich kein Modul Arguments für Oberon (wg.
Demo-Version. Aber so ist es eh kürzer!
*)
PROCEDURE GetArg (num:SHORTINT; VAR arg:ARRAY OF CHAR);
VAR
i,j:INTEGER;
dcb : POINTER TO ARRAY 256 OF CHAR;
BEGIN
dcb := ol.dosCmdBuf;
err := 0;
i := 0; j := 0;
REPEAT
INC(j,i);
i := 0;
REPEAT
INC(i);
UNTIL (i=4) OR (dcb[i+j]=0AX);
INC(err);
UNTIL err = num;
err := 0;
WHILE err < i DO
arg[err]:=dcb[err+j];
INC(err);
END;
arg[i]:=0X;
END GetArg;
(*------ Is there a disk inserted? ------*)
PROCEDURE ChangeState(device: INTEGER): BOOLEAN;
(* returns TRUE if disk in drive *)
BEGIN
DiskReqBlock^.req.command := td.changeState;
IF e.DoIO(DiskReqBlock)=0 THEN END;
RETURN 0=DiskReqBlock^.req.actual;
END ChangeState;
(*------ Is argument a disk device ? ------*)
PROCEDURE TestArg (str : ARRAY OF CHAR) : BOOLEAN;
BEGIN
IF (LEN(str) = 4) AND (CAP(str[0])="D") AND (CAP(str[1])="F")
AND (str[3] =":") AND (str[2]<="4") AND ("0"<=str[2]) THEN
RETURN TRUE;
END;
RETURN FALSE;
END TestArg;
(*--------------- main ------------------*)
BEGIN
IF ol.wbStarted THEN
HALT(20);
END;
GetArg(1,argument);
IF argument = "?" THEN
io.WriteString("DiskInDrive V1.2");io.WriteLn;
io.WriteString("Usage: DiskInDrive {DF0:|DF1:|DF2:|DF3:}\n");
ELSIF TestArg(argument) THEN
drive := ORD(argument[2])-ORD("0");
err := OpenTrackDisk(drive);
IF err = 0 THEN
IF ChangeState(drive) THEN
CloseTrackDisk(drive);
io.WriteString("There is a disk in drive ");
io.WriteString(argument);io.WriteLn;
ELSE
CloseTrackDisk(drive);
io.WriteString("No disk in drive ");
io.WriteString(argument);io.WriteLn;
HALT(5);
END; (* ChangeState *)
ELSE (* err=0 *)
io.WriteString("Dos Error:");io.WriteInt(err,4);io.WriteLn;
HALT(10);
END; (* err=0 *)
ELSE
io.WriteString("Bad Arg!\n");
HALT(10);
END; (* IF TestArg *)
END DiskInDrive.